<?php
Class V_Auth {
    public static function  authUser() {
        if ((isset ($_POST['userlogin']))) {
            if (isset($_POST['userlogin']) and isset($_POST['userpass'])) {
            	$templogin=V_DB::escape($_POST['userlogin']);
            	$temppass=V_DB::escape(md5($_POST['userpass'].'666'));
            	$tempuser=V_DB::fetch('SELECT id, pass, login, group_id FROM v_user_list '.
            							'WHERE login="'.$templogin.'" AND pass="'.$temppass.'"');
            	if (!empty($tempuser) and sizeof($tempuser)>0) {
                	$_SESSION['auth']=true;
                	$_SESSION['pass']=$tempuser['pass'];
                	$_SESSION['login']=$tempuser['login'];
                	V_DB::insertArray('v_user_list_dates',Array(
            			Array ('name' => 'user_id','value' => '"'.$tempuser['id'].'"'),
            			Array ('name' => 'user_ip','value' => '"'.$_SERVER['REMOTE_ADDR'].'"'),
            			Array ('name' => 'date','value' => 'NOW()'),
            			Array ('name' => 'action','value' => '"login"'),
                	));
                	V_Router::setPage(V_User::getDefaultPage($tempuser['group_id']));
            	} else {
            		V_DB::insertArray('v_user_list_dates',Array(
            			Array ('name' => 'user_id','value' => '0'),
            			Array ('name' => 'user_ip','value' => '"'.$_SERVER['REMOTE_ADDR'].'"'),
            			Array ('name' => 'date','value' => 'NOW()'),
            			Array ('name' => 'action','value' => '"error"'),
                	));
                	V_Router::setPage(V_User::getDefaultPage($tempuser['group_id']));
            	}
            }
  	};
    }
}